(function($, doc) {
	$.init();
	$.plusReady(function() {
		var c1 = 60;
		var userinfo = app.getState() || {};
		var device = {
				IMEI: plus.device.imei,
				IMSI: '',
				Model: plus.device.model,
				Vendor: plus.device.vendor,
				UUID: plus.device.uuid,
				Screen: plus.screen.resolutionWidth * plus.screen.scale + 'x' + plus.screen.resolutionHeight * plus.screen.scale + '',
				DPI: plus.screen.dpiX + 'x' + plus.screen.dpiY,
				OS: new Object()
			};
			for(var i = 0; i < plus.device.imsi.length; i++) {
				device.IMSI += plus.device.imsi[i];
			}
			var types = {};
			types[plus.networkinfo.CONNECTION_UNKNOW] = '未知网络';
			types[plus.networkinfo.CONNECTION_NONE] = '未连接网络';
			types[plus.networkinfo.CONNECTION_ETHERNET] = '有线网络';
			types[plus.networkinfo.CONNECTION_WIFI] = 'WiFi网络';
			types[plus.networkinfo.CONNECTION_CELL2G] = '2G蜂窝网络';
			types[plus.networkinfo.CONNECTION_CELL3G] = '3G蜂窝网络';
			types[plus.networkinfo.CONNECTION_CELL4G] = '4G蜂窝网络';
			device.NetworkInfo = types[plus.networkinfo.getCurrentType()];
			device.OS = {
				Language: plus.os.language,
				Version: plus.os.version,
				Name: plus.os.name,
				Vendor: plus.os.vendor
			};
		
		console.log(JSON.stringify(device.UUID));
		//点击获取验证码
			doc.getElementById("getCode").addEventListener('tap', function() {
				if(c1!=60){
					return;
				}
				var t=doc.getElementById('getCode').getAttribute('data-type');
				var	phone;
				var etype;
				var area_code='';
				var random_code='';
				
				if(t && t=='update_phone'){
					phone = doc.getElementById('phone').value;
					etype=3;
					if(userinfo.mobile && userinfo.mobile==phone){
						plus.nativeUI.toast("新手机号与原手机号是一样的");
					    return;
					}
				}
				else if(t && t=='reg_phone'){
					phone = doc.getElementById('phone').value;
					area_code=doc.getElementById('area_code').value;
					etype=3;
					if(!phone || (!(/^1(3|4|5|6|7|8|9)\d{9}$/.test(phone)) && area_code=='86')) {
						plus.nativeUI.toast("手机号码格式不正确");
						return;
					}
				    random_code=doc.getElementById('random_code').value;
				    if(!random_code){
				    	plus.nativeUI.toast("随机码不能为空");
						return;
				    }
				}
				else if(t && t=='find_phone'){
					phone = doc.getElementById('phone').value;
					etype=2;
				}
				else{
					phone = userinfo.mobile;
					etype=2;
				}
				
				if(!device.UUID){
					device.UUID=Math.floor(Math.random() * 1000000000000000 + 100000000000000).toString();
				}
				var Info={'phone': phone,'etype':etype, 'area_code':area_code,'uuid':device.UUID,'random_code':random_code};
				console.log(JSON.stringify(Info));
				var btnArray = ['确定', '取消'];
				mui.confirm('我们将发送验证码短信到下面的号码：\n' + phone, '确认手机号码', btnArray, function(e) {
					if(e.index == 0) {
	
						mui.get(sendSmsurl,Info, function(res) {
							console.log(JSON.stringify(res));
							if(res.status == 1) {
								//发送短信成功
								//localStorage.setItem('_send_code', res.ck_code);
								plus.nativeUI.toast("短信验证码已发送，请注意查收");
							} else {
								if(t && t=='reg_phone'){
									document.getElementById('verify').src=apiurl+'Login/vertify?'+Math.random();
								}
								plus.nativeUI.toast(res.msg);
								document.getElementById('getCode').innerHTML = '获取验证码';
								c1 = 60;
								return;
							}
							var code1 = setInterval(function() {
								document.getElementById('getCode').innerHTML =c1 + '秒';
								c1 = c1 - 1;
								if(c1 >= 0) {
									
								} else {
									document.getElementById('getCode').innerHTML = '获取验证码';
									c1 = 60;
									clearInterval(code1);
								}
							}, 1000);
						});
	
					}
				})
	
			});
			
	})

}(mui, document));